package com.yc.jpyy.terminator.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/terminator")
public class LogDataController extends BaseController {
	
	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;

	/**
	 * 添加意见反馈信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/addOperateLog", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String addOperateLog(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		// 影响行数
		int i = 0;
		try {
			//标题
			String title = request.getParameter("title");
			//操作类型
			String operatingType = request.getParameter("operatingType");
			//操作人
			String operatingPersonnel = request.getParameter("operatingPersonnel");
			//操作时间
			String operatingTime = request.getParameter("operatingTime");
			//内容
			String operatingContent = request.getParameter("operatingContent");
			//IP地址
			String operatingIP = request.getParameter("operatingIP");
			
			if((null!=title&&!title.isEmpty())&&(null!=operatingType&&!operatingType.isEmpty())&&(null!=operatingPersonnel&&!operatingPersonnel.isEmpty())&&(null!=operatingTime&&!operatingTime.isEmpty())&&(null!=operatingIP&&!operatingIP.isEmpty())){
				Map<String, Object> valMap = new HashMap<String, Object>();
				// 添加日志
				valMap.put("Title", title);
				valMap.put("OperatingType", Integer.parseInt(operatingType));
				valMap.put("OperatingPersonnel", operatingPersonnel);
				valMap.put("OperatingTime", operatingTime);
				valMap.put("OperatingContent",operatingContent);
				valMap.put("OperatingIP", operatingIP);
				i = bizDao.addOperateLog(valMap);
				if (i > 0) {
					response.setMessage("日志添加成功!");
				} else {
					response.setErrorcode(1);
					response.setMessage("日志添加失败!");
				}
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填参数!");
			}
		} catch (Exception e) {
			System.out.println("addOperateLog："+ e.toString());
			// 异常信息
			response.setErrorcode(1);
			response.setMessage("日志添加失败，请稍候重试！");
		} finally {
			return response.toJSON();
		}

	}

}
